package cn.dengta.webapp.risk.config;

import cn.dengta.common.util.SpringUtil;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 数美风控参数配置
 */
@Component
@Getter
@Setter
@ConfigurationProperties(prefix = "webapp.yidun")
public class YidunConfig implements InitializingBean {

	/** 产品密钥ID，产品标识 **/
	String secretid;
	/** 产品私有密钥，服务端生成签名信息使用，请严格保管，避免泄露 **/
	String secretkey;
	/** 视频回调地址  /yd-stream-risk/videoImgCallback **/
	String videoCallbackUrl;
	/** 音频回调地址  /yd-stream-risk/audioCallback **/
	String audioCallbackUrl;
	/** 音频检测业务id **/
	String audioBusinessId;
	/** 视频检测业务id **/
	String videoBusinessId;
	/** 风控拦截等级 */
	Integer riskLevel = 3;
	/** 风控提示等级 */
	Integer remindLevel = 2;

	static YidunConfig config;
	public static Integer RISK_LEVEL;
	public static Integer REMIND_LEVEL;

	public static YidunConfig get() {
		YidunConfig cfg = config;
		if (cfg == null) {
			config = cfg = SpringUtil.getBean(YidunConfig.class);
		}
		return cfg;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		// 尽量自己初始化，避免 Context Refresh 导致的异常
		config = this;
		RISK_LEVEL = riskLevel;
		REMIND_LEVEL = remindLevel;
	}

}
